<?php
namespace App\Model;
use App\Common\Exception\ThrowException;


class  UcenterMember extends BaseModel
{

    /**
     * 用户模型
     * @return Member
     */
    public function getMemberModel(){
        return new Member();
    }
    /**
     * 获取用户uid
     * @param $account
     * @return array|null
     * @throws \EasySwoole\Mysqli\Exceptions\ConnectFail
     * @throws \EasySwoole\Mysqli\Exceptions\PrepareQueryFail
     * @throws \Throwable
     */
    public function getUidByAccount($account){
     return   $this->getFiledValue(['username'=>$account],'id');
    }

    /**
     * 根据uid获取帐号
     * @param $uid
     */
    public function getAccountByUid($uid)
    {
        return   $this->getFiledValue(['id'=> $uid],'username');
    }


    public function changeStatus($data){
        //如果是超级管员无法关闭
        if ((intval($data["uid"]) == (int)is_administrator($data["uid"]))) {
            throw  new ThrowException(ThrowException::EROOR_MEMBER__STATUS_ISADMIN);
        }
        if ($this->editData($this->analysisWhere(['id'=>$data['uid']]),["status" => $data['status']])) {
           return  $this->getMemberModel()->editData($this->analysisWhere(['uid'=>$data['uid']]),["status" => $data["status"]]);
        } else {
            throw  new ThrowException(ThrowException::EROOR_MEMBER_CHANGE_STATUS);
        }
    }


}